@extends('admin.public.header')
@section('listcontent')
    <form class="layui-form">
    <div class="layui-form layuimini-form">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>邮件通知设置（QQ邮箱）</legend>
        </fieldset>
        <input type="hidden" name="id" value="{{$info->id ?? 0}}" />
        <div class="layui-form-item">
            <label class="layui-form-label">开启邮箱提醒</label>
            <div class="layui-input-block">
                @foreach($MailSettingModel->getMailStatusArr() as $k=>$v)
                    <input type="radio" name="mail_status" value="{{$k}}" title="{{$v}}" @if($k == ($info->mail_status ?? 0))checked="" @elseif(!isset($info->mail_status) && $k==0)checked="" @endif>
                @endforeach
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">发件人邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="send_mail" value="{{ $info->send_mail ?? '' }}" placeholder="请输入发件人邮箱" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">授权码</label>
            <div class="layui-input-block">
                <input type="text" name="send_pwd" value="{{ $info->send_pwd ?? '' }}" placeholder="请输入邮箱授权码" class="layui-input">
                <tip><a style="color:#1E9FFF;" target="_blank" href="http://service.mail.qq.com/cgi-bin/help?subtype=1&amp;&amp;no=1001256&amp;&amp;id=28">什么是授权码？</a></tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">发件平台名称</label>
            <div class="layui-input-block">
                <input type="text" name="send_name" value="{{ $info->send_name ?? '' }}" placeholder="请输入发件平台名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">收件人邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="receive_mail" value="{{ $info->receive_mail ?? '' }}" placeholder="请输入收件人邮箱" class="layui-input">
                <tip>多个邮箱号请使用英文逗号,分隔</tip>
            </div>
        </div>
        <div class="hr-line"></div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" id="saveBtn" lay-submit lay-filter="saveBtn">保存</button>
            </div>
        </div>

    </div>
    </form>
@endsection

@section('listscript')
    <script type="text/javascript">
        layui.use(['iconPickerFa', 'form', 'layer', 'upload', 'xmSelect'], function () {
            var iconPickerFa = layui.iconPickerFa,
                form = layui.form,
                layer = layui.layer,
                upload = layui.upload,
                xmSelect = layui.xmSelect,
                $ = layui.$;
            
            //监听提交
            form.on('submit(saveBtn)', function(data){
                $("#saveBtn").addClass("layui-btn-disabled");
                $("#saveBtn").attr('disabled', 'disabled');
                var loading = layer.msg('加载中..', {icon: 16,shade: 0.3,time: false});
                $.ajax({
                    url:'/admin/mall_setting/mail_setting',
                    type:'post',
                    data:data.field,
                    dataType:'JSON',
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                    success:function(res){
                        layer.close(loading);  //返回数据关闭loading
                        if(res.code==0){
                            layer.msg(res.message,{icon: 1},function (){
                                location.reload();
                            });
                        }else{
                            layer.msg(res.message,{icon: 2});
                            $("#saveBtn").removeClass("layui-btn-disabled");
                            $("#saveBtn").removeAttr('disabled');
                        }
                    },
                    error:function (data) {
                        layer.msg(res.message,{icon: 2});
                        $("#saveBtn").removeClass("layui-btn-disabled");
                        $("#saveBtn").removeAttr('disabled');
                    }
                });
            });
        });
    </script>
@endsection